function Enemy(playerId,speed,attack,hp,kind,birth_x,birth_y,angle,canvasNum)
{
	this.playerId=playerId;
	this.speed=speed;
	this.attack=attack;
	this.hp=hp;
	this.birth_x=birth_x;
	this.birth_y=birth_y;
	this.curr_hp=hp;
	this.canvasNum=canvasNum;

	this.screen_x=769;
	this.screen_y=515;
	this.x=769;
	this.y=515;
	this.length_x=50;
	this.length_y=100;
	this.position=1;
	this.score=0;
	this.angle=angle;
	this.playerBomb="player_bomb";
	this.alive=1;
	this.goCircle=1;
	this.moved=0;
	this.delay=1;
	this.lastBullet=-1;
	this.lastSuper=-1;
	this.superState=0;
	this.kind=kind;

	this.K_UP=false;
	this.K_XX=false;
	this.K_ZZ=false;
	this.K_DOWN=false;
	this.K_LEFT=false;
	this.K_RIGHT=false;
}

Enemy.prototype.draw = function()
{
	
		
		var img_playerBomb = document.getElementById(this.playerBomb);//get the bomb image object element

		if(this.goCircle==1){
			if(this.alive==1){
				g.save();
				
				g.translate(this.birth_x,this.birth_y);
				if((  Math.abs( ((1/(Math.PI*2)) * this.angle) %(Math.PI*2) )<=(Math.PI/2))||(Math.abs( ((1/(Math.PI*2)) * this.angle) %(Math.PI*2) )>=(Math.PI*1.5))){
					g.fillStyle="#7A378B";
					g.fillRect(-this.length_x/2+8, -this.length_y/2-2,this.hp/5+4,9);
					g.fillStyle="black";
					g.fillRect(-this.length_x/2+10, -this.length_y/2,this.hp/5,5);
					g.fillStyle="red";
					g.fillRect(-this.length_x/2+10, -this.length_y/2,this.curr_hp/5,5);
					g.fillStyle="black";
				}
				else {
					g.fillStyle="#7A378B";
					g.fillRect(-this.length_x/2+8, -this.length_y/2+this.speed-2,this.hp/5+4,9);
					g.fillStyle="black";
					g.fillRect(-this.length_x/2+10, -this.length_y/2+this.speed,this.hp/5,5);
					g.fillStyle="red";
					g.fillRect(-this.length_x/2+10, -this.length_y/2+this.speed,this.curr_hp/5,5);
					g.fillStyle="black";
				}
				
				g.rotate( (1/(Math.PI*2)) * this.angle );
				//绘制阴影
				//g.drawImage(img_playerShadow, this.birth_x-10, this.birth_y+20, this.length_x, this.length_y) ;
				
				//绘制飞机
				//alert(canvas[0]);
				if(this.superState==1){
					if(this.kind==1){
						g.drawImage(speedUp, -this.length_x/2+5, -this.length_y/2-10+60 , 40, 171) ;
					}
					else if(this.kind==2){
						g.drawImage(noHurt, -this.length_x/2-30, -this.length_y/2-10 , 110, 110) ;
					}
					
				}
				g.drawImage(canvas[this.canvasNum], -this.length_x/2, -this.length_y/2 , this.length_x, this.length_y) ;
				g.restore();
			}

			
		}
		else if(this.goCircle==0){
			

			if(this.alive==1){
				g.save();
				g.translate(this.birth_x,this.birth_y);
				
				
				
				//绘制阴影
				//g.drawImage(img_playerShadow, this.birth_x-10, this.birth_y+20, this.length_x, this.length_y) ;
				
				
				//绘制飞机
				if(this.position==1){	
					g.fillStyle="#7A378B";
					g.fillRect(-this.length_x/2+8, -this.length_y/2+this.speed-2,this.hp/5+4,9);
					g.fillStyle="black";
					g.fillRect(-this.length_x/2+10, -this.length_y/2+this.speed,this.hp/5,5);
					g.fillStyle="red";
					g.fillRect(-this.length_x/2+10, -this.length_y/2+this.speed,this.curr_hp/5,5);
					g.fillStyle="black";
					
					g.rotate( (1/(Math.PI*2)) * this.angle );
					if(this.superState==1){
						if(this.kind==1){
							g.drawImage(speedUp, -this.length_x/2+5, -this.length_y/2-10+60+this.speed , 40, 171) ;
						}
						else if(this.kind==2){
							g.drawImage(noHurt, -this.length_x/2-30, -this.length_y/2-10 +this.speed, 110, 110) ;
						}
						
					}
					g.drawImage(canvas[this.canvasNum], -this.length_x/2, (-this.length_y/2)+this.speed , this.length_x, this.length_y);
				}
				else {
					if(  Math.abs( ((1/(Math.PI*2)) * this.angle) %(Math.PI*2) )<=(Math.PI/2)){
						g.fillStyle="#7A378B";
						g.fillRect(-this.length_x/2+8, -this.length_y/2-this.speed-2,this.hp/5+4,9);
						g.fillStyle="black";
						g.fillRect(-this.length_x/2+10, -this.length_y/2-this.speed,this.hp/5,5);
						g.fillStyle="red";
						g.fillRect(-this.length_x/2+10, -this.length_y/2-this.speed,this.curr_hp/5,5);
						g.fillStyle="black";
					}
					else {
						g.fillStyle="#7A378B";
						g.fillRect(-this.length_x/2+8, -this.length_y/2+this.speed*2-2,this.hp/5+4,9);
						g.fillStyle="black";
						g.fillRect(-this.length_x/2+10, -this.length_y/2+this.speed*2,this.hp/5,5);
						g.fillStyle="red";
						g.fillRect(-this.length_x/2+10, -this.length_y/2+this.speed*2,this.curr_hp/5,5);
						g.fillStyle="black";
					}
					
					g.rotate( (1/(Math.PI*2)) * this.angle );
					if(this.superState==1){
						if(this.kind==1){
							g.drawImage(speedUp, -this.length_x/2+5, -this.length_y/2-10+60-this.speed , 40, 171) ;
						}
						else if(this.kind==2){
							g.drawImage(noHurt, -this.length_x/2-30, -this.length_y/2-10 -this.speed, 110, 110) ;
						}
						
					}
					g.drawImage(canvas[this.canvasNum], -this.length_x/2, -this.length_y/2-this.speed, this.length_x, this.length_y) ;
					
				}
				if(this.moved==1){
					if(this.position==1){
						this.birth_x=this.birth_x+this.speed*(Math.sin((1/(Math.PI*2)) * this.angle));
						this.birth_y=this.birth_y-this.speed*(Math.cos((1/(Math.PI*2)) * this.angle));
					}
					else{
						this.birth_x=this.birth_x-this.speed*(Math.sin((1/(Math.PI*2)) * this.angle));
						this.birth_y=this.birth_y+this.speed*(Math.cos((1/(Math.PI*2)) * this.angle));
					}
					this.moved=0;
				}
				g.restore();
			}
			
			
		}
		else if(this.goCircle==3){
			if(this.alive==1){
				g.save();
			
				g.translate(this.birth_x,this.birth_y);
				
				

				//绘制阴影
				//g.drawImage(img_playerShadow, this.birth_x-10, this.birth_y+20, this.length_x, this.length_y) ;
				
				
				
				//绘制飞机
				if(this.position==1){
					g.fillStyle="#7A378B";
					g.fillRect(-this.length_x/2+8, -this.length_y/2+this.speed-2,this.hp/5+4,9);
					g.fillStyle="black";
					g.fillRect(-this.length_x/2+10, -this.length_y/2+this.speed,this.hp/5,5);
					g.fillStyle="red";
					g.fillRect(-this.length_x/2+10, -this.length_y/2+this.speed,this.curr_hp/5,5);
					g.fillStyle="black";
					
					g.rotate( (1/(Math.PI*2)) * this.angle );
					if(this.superState==1){
						if(this.kind==1){
							g.drawImage(speedUp, -this.length_x/2+5, -this.length_y/2-10+60+this.speed , 40, 171) ;
						}
						else if(this.kind==2){
							g.drawImage(noHurt, -this.length_x/2-30, -this.length_y/2-10 +this.speed, 110, 110) ;
						}
						
					}
					g.drawImage(canvas[this.canvasNum], -this.length_x/2, -this.length_y/2+this.speed , this.length_x, this.length_y);
					
				}
				else {
					if(  Math.abs( ((1/(Math.PI*2)) * this.angle) %(Math.PI*2) )<=(Math.PI/2)){
						g.fillStyle="#7A378B";
						g.fillRect(-this.length_x/2+8, -this.length_y/2-this.speed-2,this.hp/5+4,9);
						g.fillStyle="black";
						g.fillRect(-this.length_x/2+10, -this.length_y/2-this.speed,this.hp/5,5);
						g.fillStyle="red";
						g.fillRect(-this.length_x/2+10, -this.length_y/2-this.speed,this.curr_hp/5,5);
						g.fillStyle="black";
					}
					else {
						g.fillStyle="#7A378B";
						g.fillRect(-this.length_x/2+8, -this.length_y/2+this.speed*2-2,this.hp/5+4,9);
						g.fillStyle="black";
						g.fillRect(-this.length_x/2+10, -this.length_y/2+this.speed*2,this.hp/5,5);
						g.fillStyle="red";
						g.fillRect(-this.length_x/2+10, -this.length_y/2+this.speed*2,this.curr_hp/5,5);
						g.fillStyle="black";
					}
					
					g.rotate( (1/(Math.PI*2)) * this.angle );
					if(this.superState==1){
						if(this.kind==1){
							g.drawImage(speedUp, -this.length_x/2+5, -this.length_y/2-10+60-this.speed , 40, 171) ;
						}
						else if(this.kind==2){
							g.drawImage(noHurt, -this.length_x/2-30, -this.length_y/2-10 -this.speed, 110, 110) ;
						}
						
					}
					g.drawImage(canvas[this.canvasNum], -this.length_x/2, -this.length_y/2-this.speed, this.length_x, this.length_y) ;
					
				}
				if(this.moved==1){
					if(this.position==1){
						this.birth_x=this.birth_x+this.speed*(Math.sin((1/(Math.PI*2)) * this.angle));
						this.birth_y=this.birth_y-this.speed*(Math.cos((1/(Math.PI*2)) * this.angle));
					}
					else{
						this.birth_x=this.birth_x-this.speed*(Math.sin((1/(Math.PI*2)) * this.angle));
						this.birth_y=this.birth_y+this.speed*(Math.cos((1/(Math.PI*2)) * this.angle));
					}
					this.moved=0;
				}
				g.restore();
			}

		}
		else {
			if(this.alive==1){
				
				if(this.birth_x<20){
					if(this.superState==1){
						if(this.kind==1){
							g.drawImage(speedUp, -this.length_x/2+5, -this.length_y/2-10+60, 40, 171) ;
						}
						else if(this.kind==2){
							g.drawImage(noHurt, -this.length_x/2-30, -this.length_y/2-10 , 110, 110) ;
						}
						
					}
					g.drawImage(canvas[this.canvasNum], 21, this.birth_y , this.length_x, this.length_y) ;
					this.birth_x=21;
				}
				else if (((this.birth_x) > (this.screen_x-20)))
				{	
					if(this.superState==1){
						if(this.kind==1){
							g.drawImage(speedUp, -this.length_x/2+5, -this.length_y/2-10+60, 40, 171) ;
						}
						else if(this.kind==2){
							g.drawImage(noHurt, -this.length_x/2-30, -this.length_y/2-10 , 110, 110) ;
						}
						
					}
					g.drawImage(canvas[this.canvasNum], (this.screen_x-21), this.birth_y , this.length_x, this.length_y) ;
					this.birth_x=(this.screen_x-21);
				}
				else if ((this.birth_y < (-this.length_x/2)))
				{
					if(this.superState==1){
						if(this.kind==1){
							g.drawImage(speedUp, -this.length_x/2+5, -this.length_y/2-10+60, 40, 171) ;
						}
						else if(this.kind==2){
							g.drawImage(noHurt, -this.length_x/2-30, -this.length_y/2-10 , 110, 110) ;
						}
						
					}
					g.drawImage(canvas[this.canvasNum], this.birth_x, (-this.length_x/2)+1 , this.length_x, this.length_y) ;
					this.birth_y=(-this.length_x/2)+1;
				}
				else if ((this.birth_y > (this.screen_y)))
				{
					if(this.superState==1){
						if(this.kind==1){
							g.drawImage(speedUp, -this.length_x/2+5, -this.length_y/2-10+60, 40, 171) ;
						}
						else if(this.kind==2){
							g.drawImage(noHurt, -this.length_x/2-30, -this.length_y/2-10 , 110, 110) ;
						}
						
					}
					g.drawImage(canvas[this.canvasNum], this.birth_x, (this.screen_y)-1 , this.length_x, this.length_y) ;
					this.birth_y=(this.screen_y)-1;
				}
				else
				{
					if(this.superState==1){
						if(this.kind==1){
							g.drawImage(speedUp, -this.length_x/2+5, -this.length_y/2-10+60, 40, 171) ;
						}
						else if(this.kind==2){
							g.drawImage(noHurt, -this.length_x/2-30, -this.length_y/2-10 , 110, 110) ;
						}
						
					}
					g.drawImage(canvas[this.canvasNum], this.birth_x, this.birth_y , this.length_x, this.length_y) ;
				}
				
				
			}
		}
};







Enemy.prototype.addBullet1=function()
{
	
	if((this.kind==3)&&(this.superState==1)){
		if(this.onFire==1){
			m_fire1.play();
			this.onFire++;
		}
		else if(this.onFire==2){
			m_fire2.play();
			this.onFire++;
		}
		else if(this.onFire==3){
			m_fire3.play();
			this.onFire++;
		}
		else if(this.onFire==4){
			m_fire1.play();
			this.onFire=1;
		}
		var bullet = new Bullet1(this.birth_x-15+(Math.sin((1/(Math.PI*2)) * this.angle))*(this.length_y/2),this.birth_y-(Math.cos((1/(Math.PI*2)) * this.angle))*(this.length_y/2),this.angle,this.attack*1.2,this.playerId,(enemy_bullets.length));
		enemy_bullets.push(bullet);
		var bullet2 = new Bullet1(this.birth_x+(Math.sin((1/(Math.PI*2)) * this.angle))*(this.length_y/2),this.birth_y-(Math.cos((1/(Math.PI*2)) * this.angle))*(this.length_y/2),this.angle,this.attack*1.2,this.playerId,(enemy_bullets.length));
		enemy_bullets.push(bullet2);
		var bullet3 = new Bullet1(this.birth_x+15+(Math.sin((1/(Math.PI*2)) * this.angle))*(this.length_y/2),this.birth_y-(Math.cos((1/(Math.PI*2)) * this.angle))*(this.length_y/2),this.angle,this.attack*1.2,this.playerId,(enemy_bullets.length));
		enemy_bullets.push(bullet3);
	}
	else {
		if(this.onFire==1){
			m_fire1.play();
			this.onFire++;
		}
		else if(this.onFire==2){
			m_fire2.play();
			this.onFire++;
		}
		else if(this.onFire==3){
			m_fire3.play();
			this.onFire++;
		}
		else if(this.onFire==4){
			m_fire1.play();
			this.onFire=1;
		}
		var bullet = new Bullet1(this.birth_x+(Math.sin((1/(Math.PI*2)) * this.angle))*(this.length_y/2),this.birth_y-(Math.cos((1/(Math.PI*2)) * this.angle))*(this.length_y/2),this.angle,this.attack,this.playerId,(enemy_bullets.length));
		enemy_bullets.push(bullet);
	}
};
Enemy.prototype.superZZ=function()
{
	if(this.kind==1){
		this.speed=(this.speed)*3;
		this.superState=1;
		
	}
	else if(this.kind==2){
		this.superState=1;
		
	}
	else if(this.kind==3){
		
		this.superState=1;
		m_fire4.play();
		this.addBullet1();
	}
	else if(this.kind==0){
		var bullet = new Bullet1(this.birth_x+(Math.sin((1/(Math.PI*2)) * this.angle))*(this.length_y/2),this.birth_y-(Math.cos((1/(Math.PI*2)) * this.angle))*(this.length_y/2),this.angle,(this.attack*2+70),this.playerId,(enemy_bullets.length));
		enemy_bullets.push(bullet);
		var bullet2 = new Bullet1(this.birth_x+(Math.sin((1/(Math.PI*2)) * this.angle))*(this.length_y/2),this.birth_y-(Math.cos((1/(Math.PI*2)) * this.angle))*(this.length_y/2),this.angle+45,(this.attack*2+70),this.playerId,(enemy_bullets.length));
		enemy_bullets.push(bullet2);
		var bullet3 = new Bullet1(this.birth_x+(Math.sin((1/(Math.PI*2)) * this.angle))*(this.length_y/2),this.birth_y-(Math.cos((1/(Math.PI*2)) * this.angle))*(this.length_y/2),this.angle+90,(this.attack*2+70),this.playerId,(enemy_bullets.length));
		enemy_bullets.push(bullet3);
		var bullet4 = new Bullet1(this.birth_x+(Math.sin((1/(Math.PI*2)) * this.angle))*(this.length_y/2),this.birth_y-(Math.cos((1/(Math.PI*2)) * this.angle))*(this.length_y/2),this.angle+135,(this.attack*2+70),this.playerId,(enemy_bullets.length));
		enemy_bullets.push(bullet4);
		var bullet5 = new Bullet1(this.birth_x+(Math.sin((1/(Math.PI*2)) * this.angle))*(this.length_y/2),this.birth_y-(Math.cos((1/(Math.PI*2)) * this.angle))*(this.length_y/2),this.angle+180,(this.attack*2+70),this.playerId,(enemy_bullets.length));
		enemy_bullets.push(bullet5);
		var bullet6 = new Bullet1(this.birth_x+(Math.sin((1/(Math.PI*2)) * this.angle))*(this.length_y/2),this.birth_y-(Math.cos((1/(Math.PI*2)) * this.angle))*(this.length_y/2),this.angle-45,(this.attack*2+70),this.playerId,(enemy_bullets.length));
		enemy_bullets.push(bullet6);
		var bullet7 = new Bullet1(this.birth_x+(Math.sin((1/(Math.PI*2)) * this.angle))*(this.length_y/2),this.birth_y-(Math.cos((1/(Math.PI*2)) * this.angle))*(this.length_y/2),this.angle-90,(this.attack*2+70),this.playerId,(enemy_bullets.length));
		enemy_bullets.push(bullet7);
		var bullet8 = new Bullet1(this.birth_x+(Math.sin((1/(Math.PI*2)) * this.angle))*(this.length_y/2),this.birth_y-(Math.cos((1/(Math.PI*2)) * this.angle))*(this.length_y/2),this.angle-135,(this.attack*2+70),this.playerId,(enemy_bullets.length));
		enemy_bullets.push(bullet8);
		this.superState=1;
		
	}
};
	
Enemy.prototype.keymove=function()
{
	var v = this.speed;
	if(this.K_UP){
		if((this.birth_x < 20)||((this.birth_x) > (this.screen_x-20))||(this.birth_y < (-this.length_x/2))||(this.birth_y > (this.screen_y))) {
			this.goCircle=4;
		}
		else{
			this.position=1;
			this.moved=1;
			this.goCircle=0;
			
			if(this.K_LEFT){
				this.position=1;
				this.moved=1;
				this.angle=this.angle-0.2;
				this.goCircle=3;
				this.K_LEFT=false;
			}
			else if(this.K_RIGHT){
				this.position=1;
				this.moved=1;
				this.angle=this.angle+0.2;
				this.goCircle=3;
				this.K_RIGHT=false;
			}
		}
		this.K_UP=false;
	}
	else if(this.K_DOWN){
		
		if((this.birth_x < 20)||((this.birth_x) > (this.screen_x-20))||(this.birth_y < (-this.length_x/2))||(this.birth_y > (this.screen_y))) {
			this.goCircle=4;
		}
		else {
			this.position=0;
			this.moved=1;
			this.goCircle=0;
			
			if(this.K_LEFT){
				this.position=0;
				this.moved=1;
				this.angle=this.angle-0.2;
				this.goCircle=3;
				this.K_LEFT=false;
			}
			else if(this.K_RIGHT){
				this.position=0;
				this.moved=1;
				this.angle=this.angle+0.2;
				this.goCircle=3;
				this.K_RIGHT=false;
			}
		}
		this.K_DOWN=false;
	}
	else if(this.K_LEFT){
		this.angle=this.angle-0.2;
		this.goCircle=1;
		this.K_LEFT=false;
	}
	else if(this.K_RIGHT){
		this.angle=this.angle+0.2;
		this.goCircle=1;
		this.K_RIGHT=false;
	}
	

	if(this.K_XX){
		if((this.lastBullet==-1)||((time-this.lastBullet)>(this.delay*34))){
			this.addBullet1();
			this.lastBullet=time;
			this.K_XX=false;
		}
		
	}
	else if(this.K_ZZ){
		if((this.lastSuper==-1)||((time-this.lastSuper)>(this.delay*1000))){
			this.superZZ();
			this.lastSuper=time;
			this.K_ZZ=false;
		}
		
	}
	else {
		
	}
	
};

Enemy.prototype.update=function()
{
	if(this.curr_hp<=0){
		this.alive=0;
		music_i+=1;
		m_die[music_i-1].play();
		death_num+=1;
		deathNum.innerHTML=death_num;
	}
	this.keymove();
};